
#include "base_types.h"
#include "log.h"

// ============================================================================

int Cmp (const void* _p1, const void* _p2, int size)
{
    const unsigned char* p1 = (const unsigned char*) _p1;
    const unsigned char* p2 = (const unsigned char*) _p2;

    for (int i = 0; i < size; i++)
    {
        if (*p1 > *p2)
            return 1;

        if (*p1 < *p2)
            return -1;

        p1++;
        p2++;
    }

    return 0;
}

// ============================================================================

void PRIORITY_VECTOR_SHORT::Dump (BRIDGE* bridge, int port, int tree) const
{
	LOG (bridge, port, tree, "{BID}--{D7}--{BID}--{D7}--{BID}--{X4}",
		&RootId,
		(int) ExternalRootPathCost.GetValue (),
		&RegionalRootId,
		(int) InternalRootPathCost.GetValue (),
		&DesignatedBridgeId,
		(int) DesignatedPortId.GetValue ());
};

// ============================================================================

void BRIDGE_ADDRESS::Dump (BRIDGE* bridge, int port, int tree) const
{
	LOG (bridge, port, tree, "{X2}{X2}{X2}{X2}{X2}{X2}", a0, a1, a2, a3, a4, a5);
}

// ============================================================================

void BRIDGE_ID::Dump (BRIDGE* bridge, int port, int tree) const
{
	LOG (bridge, port, tree, "{X4}.{BA}", this->_priority.GetValue (), &this->_address);
}

// ============================================================================

const char* GetPortRoleName (PORT_ROLE role)
{
	if (role == PORT_ROLE_MASTER)
		return "Master";
	else if (role == PORT_ROLE_ROOT)
		return "Root";
	else if (role == PORT_ROLE_DESIGNATED)
		return "Designated";
	else if (role == PORT_ROLE_ALTERNATE)
		return "Alternate";
	else if (role == PORT_ROLE_BACKUP)
		return "Backup";
	else if (role == PORT_ROLE_DISABLED)
		return "Disabled";
	else
	{
		assert (false);
		return NULL;
	}
}


